package secondStage.part2.包装类.日期工具类;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @ClassName: [DateUtils]
 * @Description: 日期工具类
 * @Author: [黄劲松]
 * @CreateDate: [2021-03-28]
 * @Version: [v1.0]
 */
/*
    构造方法私有
    成员方法静态
*/
public class DateUtils {
    private DateUtils() {
    }

    /*
    把日期转为指定格式的字符串
    返叵值类型:String
    参数：Date date,String format
     */
    public static String dateToString(Date date, String format) {
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        String s = sdf.format(date);
        return s;
    }

    /*
    把日期转为指定格式的字符串
    返回值值类型:String
    参数：Date date,String format
    */
    public static Date stringToDate(String s, String format) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        Date d = sdf.parse(s);
        return d;
    }
}
